<!DOCTYPE html>
<html lang="zh-cn">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title></title>
		<style>
			
		</style>
		<script>
			// 做劫持用的
			function observer(data){
				return new Proxy(data,{
					get(target,attr){
						return target[attr]
					},
					set(target,attr,newValue){
						target[attr] = newValue;
						title.innerHTML = newValue;
					}
				});
			}

			// http://es6.ruanyifeng.com/#docs/proxy

		</script>
	</head>

	<body>
		<div id="app">
			<button id="btn">设置</button>
			<p id="title"></p>
		</div>
		<script>
			let title = document.querySelector('#title')
			let btn = document.querySelector('#btn')
			let data = {
				title: 'hello,测试',
				message: 'hello,测试'
			}

			// 劫持
			data = observer(data)

			title.innerHTML = data.title;

			btn.onclick = function (){
				data.title = '改变了'
			}

		</script>
	</body>
</html>